import type { PageParam, PageResult } from '@vben/request';

// 资源类型枚举
export enum ResourceType {
  ALGORITHM = 'algorithm', // 算法资源
  CAPABILITY = 'capability', // 技术能力资源
  DATA = 'data', // 数据资源
  ENTITY = 'entity', // 实体资源
  MODEL = 'model', // 模型资源
  SERVICE = 'service', // 服务资源
}

// 资源分类枚举
export enum ResourceCategory {
  AI_SERVICE = 'ai_service', // AI服务
  ANALYTICS = 'analytics', // 分析算法
  API = 'api', // API
  AUTHENTICATION = 'authentication', // 认证

  // 服务分类
  BOOKING = 'booking', // 预订
  // 模型分类
  BUSINESS_MODEL = 'business_model', // 业务模型
  CACHE = 'cache', // 缓存
  DATA_MODEL = 'data_model', // 数据模型

  // 数据分类
  DATABASE = 'database', // 数据库
  // 实体分类
  EQUIPMENT = 'equipment', // 设备
  FILE = 'file', // 文件
  FORM = 'form', // 表单
  INTEGRATION = 'integration', // 集成
  // 算法分类
  ML_MODEL = 'ml_model', // 机器学习模型

  NOTIFICATION = 'notification', // 通知
  PAYMENT = 'payment', // 支付
  PROCESS_MODEL = 'process_model', // 流程模型
  PRODUCT = 'product', // 商品

  REPORT = 'report', // 报表
  ROOM = 'room', // 房间
  RULE = 'rule', // 规则

  STREAM = 'stream', // 流数据
  USER = 'user', // 用户
  // 技术能力分类
  WORKFLOW = 'workflow', // 工作流
}

// 资源状态枚举
export enum ResourceStatus {
  ACTIVE = 'active', // 激活
  ARCHIVED = 'archived', // 归档
  DEPRECATED = 'deprecated', // 废弃
  DRAFT = 'draft', // 草稿
  INACTIVE = 'inactive', // 停用
}

// 资源属性类型
export interface ResourceAttribute {
  id: string;
  name: string;
  type: 'array' | 'boolean' | 'date' | 'number' | 'object' | 'string';
  value: any;
  required: boolean;
  description?: string;
  validation?: {
    enum?: any[];
    max?: number;
    min?: number;
    pattern?: string;
  };
}

// 资源属性集合
export interface ResourceAttributes {
  [key: string]: ResourceAttribute;
}

// 资源能力类型
export interface ResourceCapability {
  id: string;
  name: string;
  type: 'api' | 'form' | 'integration' | 'report' | 'rule' | 'workflow';
  description: string;
  version: string;
  config: any;
  enabled: boolean;
  dependencies?: string[]; // 依赖的其他能力ID
}

// 资源能力集合
export interface ResourceCapabilities {
  [key: string]: ResourceCapability;
}

// 资源约束类型
export interface ResourceConstraint {
  id: string;
  name: string;
  type: 'access' | 'business' | 'quantity' | 'technical' | 'time';
  description: string;
  condition: {
    field: string;
    operator:
      | 'contains'
      | 'eq'
      | 'gt'
      | 'gte'
      | 'in'
      | 'lt'
      | 'lte'
      | 'ne'
      | 'not_in'
      | 'regex';
    value: any;
  };
  enabled: boolean;
}

// 资源约束集合
export interface ResourceConstraints {
  [key: string]: ResourceConstraint;
}

// 价格模型类型
export interface PriceModel {
  id: string;
  name: string;
  type: 'auction' | 'fixed' | 'subscription' | 'tiered' | 'usage';
  description: string;

  // 客户侧定价
  customerPricing: {
    basePrice: number;
    currency: string;
    discounts?: Array<{
      conditions?: any;
      type: 'fixed' | 'percentage';
      value: number;
    }>;
    tiers?: Array<{
      max?: number;
      min: number;
      price: number;
    }>;
    unitPrice?: number;
  };

  // 平台侧定价
  platformPricing: {
    commission?: number;
    cost: number;
    margin: number;
    revenueShare?: number;
  };

  enabled: boolean;
}

// 资源价格集合
export interface ResourcePricing {
  [key: string]: PriceModel;
}

// 资源生命周期
export interface ResourceLifecycle {
  status: ResourceStatus;
  createdAt: string;
  updatedAt: string;
  publishedAt?: string;
  deprecatedAt?: string;
  archivedAt?: string;
  version: string;
  tags: string[];
}

// 资源元数据
export interface ResourceMetadata {
  creator: string;
  owner: string;
  tenant: string;
  tags: string[];
  description: string;
  documentation?: string;
  examples?: string[];
  changelog?: Array<{
    changes: string[];
    date: string;
    version: string;
  }>;
}

// 核心资源接口
export interface Resource {
  id: string;
  name: string;
  type: ResourceType;
  category: ResourceCategory;
  version: string;

  // 统一属性模型
  attributes: ResourceAttributes;

  // 统一能力模型
  capabilities: ResourceCapabilities;

  // 统一约束模型
  constraints: ResourceConstraints;

  // 统一价格模型
  pricing: ResourcePricing;

  // 生命周期
  lifecycle: ResourceLifecycle;

  // 元数据
  metadata: ResourceMetadata;
}

// 资源查询参数
export interface ResourceQueryParam extends PageParam {
  type?: ResourceType;
  category?: ResourceCategory;
  status?: ResourceStatus;
  tags?: string[];
  keyword?: string;
  owner?: string;
  tenant?: string;
}

// 资源创建参数
export interface CreateResourceParam {
  name: string;
  type: ResourceType;
  category: ResourceCategory;
  description: string;
  attributes?: ResourceAttributes;
  capabilities?: ResourceCapabilities;
  constraints?: ResourceConstraints;
  pricing?: ResourcePricing;
  tags?: string[];
}

// 资源更新参数
export interface UpdateResourceParam {
  name?: string;
  description?: string;
  attributes?: ResourceAttributes;
  capabilities?: ResourceCapabilities;
  constraints?: ResourceConstraints;
  pricing?: ResourcePricing;
  tags?: string[];
  status?: ResourceStatus;
}

// 资源分页结果
export interface ResourcePageResult extends PageResult<Resource> {}

// 资源注册结果
export interface ResourceRegistrationResult {
  success: boolean;
  resourceId: string;
  message: string;
  errors?: string[];
}

// 资源发现结果
export interface ResourceDiscoveryResult {
  resources: Resource[];

  total: number;
  facets: {
    categories: Record<ResourceCategory, number>;
    statuses: Record<ResourceStatus, number>;
    tags: Record<string, number>;
    types: Record<ResourceType, number>;
  };
}
